package com.dexilaonian.adpter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.dexilaonian.R;
import com.dexilaonian.bean.StoreBean;
import com.dexilaonian.fragment.StoreFragment;

import java.util.List;

/**
 * Created by Administrator on 2018/5/2.
 */

public class TabAdapter extends BaseAdapter{
    private final Context mContext;
    private final List<String> mTitleList;
    public TabAdapter(Context context, List<String> titleList) {
        mContext = context;
        mTitleList = titleList;
    }
    @Override
    public int getCount() {
        if (mTitleList.size() == 0) {
            return 0;
        } else {
            return mTitleList.size();
        }
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewhoder = null;
        if (convertView == null) {
            viewhoder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.tab, null);
            viewhoder.titletext = (TextView) convertView.findViewById(R.id.title_tab);
            convertView.setTag(viewhoder);
        } else {
            viewhoder = (ViewHolder) convertView.getTag();
        }
        String s = mTitleList.get(position);
        if (!TextUtils.isEmpty(s)) {
            viewhoder.titletext.setText(s);
        }
        return convertView;
    }
    class ViewHolder{
        TextView titletext;
    }
}
